package org.lex.swing.prefs;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.lex.utils.StateChangeSupport;


public class CategoryAdapter extends JPanel implements Category, ActionListener, DocumentListener, ChangeListener, PropertyChangeListener,
		ListSelectionListener {
	private static final String DEFAULT_TITLE = "(Category Title)";
	private boolean hasChanged = false;
	StateChangeSupport scs = new StateChangeSupport();

	public Component getCategoryComponent() {
		return this;
	}

	public String getTitle() {
		return DEFAULT_TITLE;
	}

	public void loadConfiguration() {
	}

	public void saveConfiguration() {
	}

	public boolean isSupported(Category.Action action) {
		return false;
	}

	public void performAction(Category.Action action) {
	}

	public boolean hasContentChanged() {
		return hasChanged;
	}

	public void addContentChangeListener(ChangeListener l) {
		scs.addChangeListener(l);
	}

	public void removeContentChangeListener(ChangeListener l) {
		scs.removeChangeListener(l);
	}

	protected void fireContentChanged(boolean value) {
		this.hasChanged = value;
		scs.fireStateChanged(this);
	}

	/**
	 * event-listeners
	 */
	// ActionListener
	public void actionPerformed(ActionEvent e) {
		this.fireContentChanged(true);
	}

	// DocumentListener
	public void changedUpdate(DocumentEvent e) {
		this.fireContentChanged(true);
	}

	public void insertUpdate(DocumentEvent e) {
		this.fireContentChanged(true);
	}

	public void removeUpdate(DocumentEvent e) {
		this.fireContentChanged(true);
	}

	// ChangeListener
	public void stateChanged(ChangeEvent e) {
		this.fireContentChanged(true);
	}

	// PropertyChangeListener
	public void propertyChange(PropertyChangeEvent e) {
		this.fireContentChanged(true);
	}

	// ListSelectionListener
	public void valueChanged(ListSelectionEvent e) {
		this.fireContentChanged(true);
	}
}
